package com.example.demo.controller;

import com.alibaba.fastjson.JSON;
import com.example.demo.dto.R;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@CrossOrigin//允许跨域
@RestController
public class TestController {

    @PostMapping("/login")
    public R login(@RequestBody Map<String, Object> report) {

        if (report.get("useranme").equals("1")) {
            return R.ok(true, "登陆成功");
        } else {
            return R.no(false, "登录失败");
        }
    }

    @GetMapping("/menus")
    public R menus() {
        return R.ok(getStringObjectMap());
    }

    private Map<String, Object> getStringObjectMap() {
        Map<String, Object> data = new HashMap<>();
        data.put("pages", JSON.parseArray("[\n" +
                "      {\n" +
                "        \"label\": \"Home\",\n" +
                "        \"url\": \"/\",\n" +
                "        \"redirect\": \"/index/1\"\n" +
                "      },\n" +
                "      {\n" +
                "        \"label\": \"示例\",\n" +
                "        \"children\": [\n" +
                "          {\n" +
                "            \"label\": \"页面A\",\n" +
                "            \"url\": \"index\",\n" +
                "            \"schema\": {\n" +
                "              \"type\": \"page\",\n" +
                "              \"title\": \"页面A\",\n" +
                "              \"body\": \"页面A\"\n" +
                "            },\n" +
                "            \"children\": [\n" +
                "              {\n" +
                "                \"label\": \"页面A-1\",\n" +
                "                \"url\": \"1\",\n" +
                "                \"schema\": {\n" +
                "                  \"type\": \"page\",\n" +
                "                  \"title\": \"页面A-1\",\n" +
                "                  \"body\": \"页面A-1\"\n" +
                "                }\n" +
                "              },\n" +
                "              {\n" +
                "                \"label\": \"页面A-2\",\n" +
                "                \"url\": \"2\",\n" +
                "                \"schema\": {\n" +
                "                  \"type\": \"page\",\n" +
                "                  \"title\": \"页面A-2\",\n" +
                "                  \"body\": \"页面A-2\"\n" +
                "                }\n" +
                "              },\n" +
                "              {\n" +
                "                \"label\": \"页面A-3\",\n" +
                "                \"url\": \"3\",\n" +
                "                \"schema\": {\n" +
                "                  \"type\": \"page\",\n" +
                "                  \"title\": \"页面A-3\",\n" +
                "                  \"body\": \"页面A-3\"\n" +
                "                }\n" +
                "              }\n" +
                "            ]\n" +
                "          },\n" +
                "          {\n" +
                "            \"label\": \"页面B\",\n" +
                "            \"badge\": 3,\n" +
                "            \"badgeClassName\": \"bg-info\",\n" +
                "            \"schema\": {\n" +
                "              \"type\": \"page\",\n" +
                "              \"title\": \"页面B\",\n" +
                "              \"body\": \"页面B\"\n" +
                "            }\n" +
                "          },\n" +
                "          {\n" +
                "            \"label\": \"页面C\",\n" +
                "            \"schema\": {\n" +
                "              \"type\": \"page\",\n" +
                "              \"title\": \"页面C\",\n" +
                "              \"body\": \"页面C\"\n" +
                "            }\n" +
                "          },\n" +
                "          {\n" +
                "            \"label\": \"列表示例\",\n" +
                "            \"url\": \"/crud\",\n" +
                "            \"rewrite\": \"/crud/list\",\n" +
                "            \"icon\": \"fa fa-cube\",\n" +
                "            \"children\": [\n" +
                "              {\n" +
                "                \"label\": \"列表\",\n" +
                "                \"url\": \"/crud/list\",\n" +
                "                \"icon\": \"fa fa-list\",\n" +
                "                \"schemaApi\": \"get:/pages/crud-list.json\"\n" +
                "              },\n" +
                "              {\n" +
                "                \"label\": \"新增\",\n" +
                "                \"url\": \"/crud/new\",\n" +
                "                \"icon\": \"fa fa-plus\",\n" +
                "                \"schemaApi\": \"get:/pages/crud-new.json\"\n" +
                "              },\n" +
                "              {\n" +
                "                \"label\": \"查看\",\n" +
                "                \"url\": \"/crud/:id\",\n" +
                "                \"schemaApi\": \"get:/pages/crud-view.json\"\n" +
                "              },\n" +
                "              {\n" +
                "                \"label\": \"修改\",\n" +
                "                \"url\": \"/crud/:id/edit\",\n" +
                "                \"schemaApi\": \"get:/pages/crud-edit.json\"\n" +
                "              }\n" +
                "            ]\n" +
                "          }\n" +
                "        ]\n" +
                "      },\n" +
                "      {\n" +
                "        \"label\": \"分组2\",\n" +
                "        \"children\": [\n" +
                "          {\n" +
                "            \"label\": \"用户管理\",\n" +
                "            \"schema\": {\n" +
                "              \"type\": \"page\",\n" +
                "              \"title\": \"用户管理\",\n" +
                "              \"body\": \"页面C\"\n" +
                "            }\n" +
                "          },\n" +
                "          {\n" +
                "            \"label\": \"外部链接\",\n" +
                "            \"link\": \"http://baidu.gitee.io/amis\"\n" +
                "          },\n" +
                "          {\n" +
                "            \"label\": \"部门管理\",\n" +
                "            \"schemaApi\": \"${API_HOST}/api/amis-mock/mock2/service/form?tpl=tpl3\"\n" +
                "          },\n" +
                "          {\n" +
                "            \"label\": \"jsonp 返回示例\",\n" +
                "            \"schemaApi\": \"jsonp:/pages/jsonp.js?callback=jsonpCallback\"\n" +
                "          }\n" +
                "        ]\n" +
                "      }\n" +
                "    ]"));
        return data;
    }

}
